// import { Page } from "@/types/storeModule"
import { assign } from 'lodash-es'

const state = {
  // 接口调用参数
  params: {
    page: {
      currentPage: 1,
      pageSize: 20,
      totalCount: 0,
      totalPage: 0,
      sortField: 'front_user_id',
      order: 'desc'
    },
    options: {}
  },
  roles: {}, // 权限
  apiName: 'frontUser',
  privileges: ['front_user_add', 'front_user_export', 'front_user_import'],
  // 列表data数据
  isLoading: false,
  tableData: [],
  searchData: [
    {
      id: 'entity.frontUserName',
      name: '用户姓名',
      type: 'text',
      hint: '用户姓名',
      defaultValue: ''
    },
    {
      id: 'entity.frontLoginname',
      name: '登录名邮箱',
      type: 'text',
      hint: '登录名邮箱',
      defaultValue: ''
    },
    {
      id: 'entity.type',
      name: '用户类型',
      type: 'select',
      hint: '用户类型',
      options: [
        {
          key: '1',
          value: 'Option1'
        },
        {
          key: '2',
          value: 'Option2'
        }
      ]
    },
    {
      id: 'entity.status',
      name: '用户状态',
      type: 'multi_select',
      hint: '用户状态',
      options: [
        {
          key: '1',
          value: 'Option1'
        },
        {
          key: '2',
          value: 'Option2'
        },
        {
          key: '3',
          value: 'Option3'
        },
        {
          key: '4',
          value: 'Option4'
        }
      ]
    },
    {
      id: 'entity.setup',
      name: '出生日期',
      type: 'date',
      hint: '出生日期',
      defaultValue: ''
    },
    {
      id: 'entity.work',
      name: '在职时间',
      type: 'time_range',
      hint: '在职时间',
      defaultValue: ''
    },
    {
      id: 'entity.reg',
      name: '注册地',
      type: 'complex',
      hint: '注册地',
      children: [
        {
          id: 'reg1',
          name: '省',
          paramName: '省',
          options: [
            {
              value: '北京',
              key: '北京'
            },
            {
              value: '上海',
              key: '上海'
            }
          ]
        },
        {
          id: 'reg2',
          name: '市',
          paramName: '市',
          options: [
            {
              value: '朝阳',
              key: '朝阳'
            },
            {
              value: '海淀',
              key: '海淀'
            }
          ]
        },
        {
          id: 'reg3',
          name: '区',
          options: [
            {
              value: '霄云路',
              key: '霄云路'
            },
            {
              value: '麦子店',
              key: '麦子店'
            }
          ]
        }
      ]
    }
  ],
  tableHeadList: [
    {
      label: '调研用户ID',
      prop: 'frontUserId'
    },
    {
      label: '登录名（邮箱）',
      prop: 'frontLoginname'
    },
    {
      label: '用户姓名',
      prop: 'frontUsername',
      slotName: 'frontUsername'
    },
    {
      label: '所属机构ID',
      prop: 'researchOrgId'
    }
  ]
}

// getters
const getters = {}

// actions
const actions = {}

// mutations
const mutations = {
  // 更新页面搜索内容
  updateSearchData(state, payload: any[]) {
    state.searchData = payload
  },
  // 更新表格 loading 状态
  updateLoading(state, payload: boolean) {
    state.isLoading = payload
  },

  // 更新数据page
  updatePage(state, payload: any) {
    state.params.page = assign(state.params.page, payload)
  },

  // 更新数据Condition
  updateCondition(state, payload: any) {
    state.params.condition = cloneDeep(payload)
  },

  // 更新data数据
  updateTableData(state, payload: any[]) {
    state.tableData = payload
  },
  // 更新列表表头数据
  updateEditTableList(state, payload: any[]) {
    state.tableHeadList = payload
  },
  // 更新列表参数数据
  updateParams(state, payload: any) {
    state.params = Object.assign({}, state.params, payload)
  },
  // 更新权限
  updateRoles(state, payload: Record<string, boolean>) {
    state.roles = payload
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
